//% color="#29be3a" iconWidth=50 iconHeight=40
namespace expansion{
        
    //% block="read [A] [B]" blockType="reporter"
    //% A.shadow="dropdown" A.options="A" 
    //% B.shadow="dropdown" B.options="B" 
    export function myBlock1(parameter: any, block: any) {
        let A= parameter.A.code
        let B= parameter.B.code
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addCode(`eunihiker.readSensor(e${A},${B})`)
    }

    //% block="pin [A] output [H]" blockType="command"
    //% A.shadow="dropdown" A.options="A" 
    //% H.shadow="dropdown" H.options="H" 
    export function myBlock2(parameter: any, block: any) {
        let A= parameter.A.code
        let H= parameter.H.code
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addCode(`eunihiker.setGpioState(e${A}, e${H});`)
    }
    //% block="pin [S] servo rotate [D] at [C] % speed" blockType="command"
    //% C.shadow="range"   C.params.min=0    C.params.max=100   C.defl=50
    //% D.shadow="dropdown" D.options="D" 
    //% S.shadow="dropdown" S.options="S" 
    export function myBlock3(parameter: any, block: any) {
        let C= parameter.C.code
        let D= parameter.D.code
        let S= parameter.S.code
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addCode(`eunihiker.setServo360(e${S},e${D}, ${C});`)
    } 
    //% block="pin [S] servo stop " blockType="command"
    //% S.shadow="dropdown" S.options="S" 
    export function myBlock31(parameter: any, block: any) {
        let S= parameter.S.code
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addCode(`eunihiker.setServo360(e${S},eStop, 0);`)
    } 
    //% block="set pin [S] servo to [E] degree" blockType="command"
    //% S.shadow="dropdown" S.options="S" 
    //% E.shadow="range"   E.params.min=0    E.params.max=360   E.defl=0
    export function myBlock4(parameter: any, block: any) {
        let S= parameter.S.code
        let E= parameter.E.code
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addCode(`eunihiker.setServoAngle(e${S}, ${E});`)
    }

    //% block="motor [M] rotate [D] at speed [G]" blockType="command"
    //% M.shadow="dropdown" M.options="M" 
    //% D.shadow="dropdown" D.options="D" 
    //% G.shadow="range"   G.params.min=0    G.params.max=255   G.defl=255
    export function myBlock5(parameter: any, block: any) {
        let M= parameter.M.code
        let D= parameter.D.code
        let G= parameter.G.code
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addSetup("myBlock768",`eunihiker.setMotorPeriod(eMotor1_2, 255);`,true)
        Generator.addSetup("myBlock76",`eunihiker.setMotorPeriod(eMotor3_4, 255);`,true)                
        Generator.addCode(`eunihiker.MotorRun(${M},e${D},${G});`)
    }
    //% block="motor stop [M]" blockType="command"
    //% M.shadow="dropdown" M.options="M" 
    export function myBlock6(parameter: any, block: any) {
        let M= parameter.M.code
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addSetup("myBlock768",`eunihiker.setMotorPeriod(eMotor1_2, 255);`,true)
        Generator.addSetup("myBlock76",`eunihiker.setMotorPeriod(eMotor3_4, 255);`,true)  
        Generator.addCode(`eunihiker.MotorRun(${M},eStop,0);`)
    }
    //% block="read battery percentage" blockType="reporter"
    export function myBlock7(parameter: any, block: any) {
        Generator.addInclude("myBlock7212",`#include "DFRobot_UnihikerExpansion.h"`,true)
        Generator.addObject("myBlock7116",`DFRobot_UnihikerExpansion_I2C`,`eunihiker(&Wire)`,true)
        Generator.addSetup("myBlock7688",`eunihiker.begin();`,true)
        Generator.addCode(`eunihiker.getBattery()`)
    }
    //%board="esp32s3bit"
    //% block="pin P1 [I] RGB LEDS" blockType="command"
    //% I.shadow="number" I.defl=4
    export function myBlock8(parameter: any, block: any) {
        let I= parameter.I.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.begin(P1, ${I});`)
    }
    //%board="microbit"   
    //% block="pin P1 [I] RGB LEDS" blockType="command"
    //% I.shadow="number" I.defl=4
    export function myBlock81(parameter: any, block: any) {
        let I= parameter.I.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.begin(1, ${I});`)
    }
    //% block="pin P1 RGB LED brightness [J]" blockType="command"
    //% J.shadow="range"   J.params.min=0    J.params.max=255   J.defl=255
    export function myBlock9(parameter: any, block: any) {
        let J= parameter.J.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.setBrightness(${J});`)
    }
    //% block="pin P1 clear all RGB LED" blockType="command"
    export function myBlock10(parameter: any, block: any) {
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.clear();`)
    }
    //% block="pin P1 [DS] to [DE] RGBs show color [COLOR]" blockType="command"
    //% DS.shadow="number" DS.defl=0
    //% DE.shadow="number" DE.defl=3
    //% COLOR.shadow="colorPalette" 
    export function myBlock11(parameter: any, block: any) {
        let DS= parameter.DS.code
        let DE= parameter.DE.code
        let COLOR= parameter.COLOR.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.setRangeColor(${DS}, ${DE}, ${COLOR});`)
    }
    //% block="red [RED] green [GREEN] blue [BLUE]" blockType="reporter"
    //% RED.shadow="range"   RED.params.min=0    RED.params.max=255   RED.defl=255
    //% GREEN.shadow="range"   GREEN.params.min=0    GREEN.params.max=255   GREEN.defl=255
    //% BLUE.shadow="range"   BLUE.params.min=0    BLUE.params.max=255   BLUE.defl=255
    export function myBlock12(parameter: any, block: any) {
        let RED= parameter.RED.code
        let GREEN= parameter.GREEN.code
        let BLUE= parameter.BLUE.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addInclude("function",`uint32_t rgbToColor(uint8_t r, uint8_t g, uint8_t b){
  return (uint32_t)((((uint32_t)r<<16) | ((uint32_t)g<<8)) | (uint32_t)b);
}`)
        Generator.addCode(`rgbToColor(round(${RED}), round(${GREEN}), round(${BLUE}))`)
    }
    //% block="pin P1 [DS] to [DE] RGBs show gradient color form [CS] to [CE]" blockType="command"
    //% DS.shadow="number" DS.defl=0
    //% DE.shadow="number" DE.defl=3
    //% CS.shadow="range"   CS.params.min=1    CS.params.max=360  CS.defl=1
    //% CE.shadow="range"   CE.params.min=1    CE.params.max=360  CE.defl=360
    export function myBlock13(parameter: any, block: any) {
        let DS= parameter.DS.code
        let DE= parameter.DE.code
        let CS= parameter.CS.code
        let CE= parameter.CE.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.showRainbow(${DS}, ${DE}, ${CS}, ${CE});`)
    }
    //% block="pin P1 shift pixels by [MOVE]" blockType="command"
    //% MOVE.shadow="number" MOVE.defl=0
    export function myBlock14(parameter: any, block: any) {
        let MOVE= parameter.MOVE.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.shift(${MOVE});`)
    }
    //% block="pin P1 rotate pixels by [XMOVE]" blockType="command"
    //% XMOVE.shadow="number" XMOVE.defl=0
    export function myBlock15(parameter: any, block: any) {
        let XMOVE= parameter.XMOVE.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.rotate(${XMOVE});`)
    }
    //% block="pin P1 clear RGB LED [NUM]" blockType="command"
    //% NUM.shadow="number" NUM.defl=0
    export function myBlock16(parameter: any, block: any) {
        let NUM= parameter.NUM.code
        Generator.addInclude("myBlock2993",`#include <DFRobot_NeoPixel.h>`,true)
        Generator.addObject("myBlock1014",`DFRobot_NeoPixel`,`neoPixel_P1`,true)
        Generator.addCode(`neoPixel_P1.setRangeColor(${NUM}, ${NUM}, 0x000000);`)
    }
}

    